//
//  ExercisesCardHeaderBarView.m
//  ShowYork
//
//  Created by hxh on 2020/10/23.
//  Copyright © 2020 hxh. All rights reserved.
//
typedef void(^doneBlock)(void);
typedef void(^resultBlock)(void);
typedef void(^moreBlock)(void);
#import "ExercisesResultHeaderBarView.h"

@interface ExercisesResultHeaderBarView ()
@property (nonatomic,strong)UIView *line;

@property (nonatomic,strong)UIButton *moreButton;
@property (nonatomic,strong)UIImageView *moreImgView;


@property (nonatomic,strong)UIButton *cardButton;
@property (nonatomic,strong)UIImageView *cardImgView;

@property (nonatomic,strong)UIButton *backBtn;
@property (nonatomic,strong)UIImageView *backImgView;
@property (nonatomic,copy)doneBlock done;
@property (nonatomic,copy)resultBlock result;
@property (nonatomic,copy)moreBlock more;
@property (nonatomic,strong)UILabel *navTitleLb;

@end

@implementation ExercisesResultHeaderBarView

- (instancetype)initWithCompleteBlock:(void (^)(void))completeBlock resultBlock:(void (^)(void))resultBlock moreBlock:(void (^)(void))moreBlock{
    if (self = [super init]) {
        
        if (completeBlock) {
            self.done = ^{
                completeBlock();
            };
        }
        if (resultBlock) {
            self.result = ^{
                resultBlock();
            };
        }
        if (moreBlock) {
            self.more = ^{
                moreBlock();
            };
        }
        [self setUI];
    }
    return self;

    
}


- (void)setUI{

    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(230, 230, 230, 1);
    [self addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.height.mas_equalTo(1);
    }];
    
    self.moreImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"course_more_tag"]];
    [self addSubview:self.moreImgView];
    [self.moreImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-16);
        make.bottom.equalTo(self).offset(-12);
    }];
    self.moreButton = [[UIButton alloc]init];
    [self.moreButton addTarget:self action:@selector(moreMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.moreButton];
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.equalTo(self);
        make.left.equalTo(self.moreImgView.mas_left).offset(-6);
        make.height.mas_equalTo(44);
    }];
    
    self.cardImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"exerciese_tag_datika"]];
    [self addSubview:self.cardImgView];
    [self.cardImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.moreImgView.mas_left).offset(-24);
        make.bottom.equalTo(self).offset(-12);
    }];
    
    self.cardButton = [[UIButton alloc]init];
    [self.cardButton addTarget:self action:@selector(cardMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.cardButton];
    [self.cardButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.left.equalTo(self.cardImgView.mas_left).offset(-6);
        make.right.equalTo(self.cardImgView.mas_right).offset(6);
        make.height.mas_equalTo(44);
    }];
    
    self.navTitleLb = [[UILabel alloc]init];
    self.navTitleLb.text = @"查看解析";
    self.navTitleLb.textColor = C35;
    self.navTitleLb.font = [UIFont boldSystemFontOfSize:18];
    [self addSubview:self.navTitleLb];
    [self.navTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.cardImgView);
        make.centerX.equalTo(self);
    }];
    
    self.backImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"common_back_tag"]];
    [self addSubview:self.backImgView];
    [self.backImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.cardImgView);
        make.left.equalTo(self).offset(16);
    }];
    
    self.backBtn = [[UIButton alloc]init];
    [self.backBtn addTarget:self action:@selector(backMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.backBtn];
    [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    
 
}
- (void)backMethod{
    if (self.done) {
        self.done();
    }
}
- (void)moreMethod{
    if (self.more) {
        self.more();
    }
}
- (void)cardMethod{
    if (self.result) {
        self.result();
    }
}
- (void)setNavTitle:(NSString *)navTitle{
    self.navTitleLb.text = navTitle;
}


@end
